import Vue from 'vue'
import Vuex from 'vuex'
import axios from "axios"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 图书列表
    bookList:[]
  },
  mutations: {
    // 赋值 bookList
    infoBookList(state, e){
      state.bookList = e
    }
  },
  actions: {
    // 获取图书 并 存到内存
    getBookList(ctx, count){
      // let params = {
      //   currentPage: 1,
      //   pagesize: count
      // }
      axios.get("/book", ).then(res => {
        ctx.commit("infoBookList", res.data)
        window.localStorage.setItem("bookList",JSON.stringify(res.data))
        console.log(res.data)
      })
    }
  },
  getters:{
    // 加工 bookList
    showBookList: state => {
      return state.bookList
    }
  },
  modules: {
  }
})
